﻿using AspectCore.Extensions.Hosting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace Handday.Erp.Core
{
    /// <summary>
    /// IHostBuilder
    /// </summary>
    public static class HostBuilderExtensions
    {
        /// <summary>
        /// ConfigureHost
        /// </summary>
        public static IHostBuilder ConfigureHost<TStartup>(this IHostBuilder hostBuilder) where TStartup : class
        {
            hostBuilder
            .ConfigureAppConfiguration((hostingContext, configurationBuilder) =>
            {
                //分布式配置中心
                configurationBuilder
                    .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
                    .LoadApolloAppSettings();
            })
            .UseDynamicProxy()
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<TStartup>()
                .UseKestrel(options =>
                {
                    options.Limits.MaxRequestBodySize = null;
                });
            });

            return hostBuilder;
        }
    }
}
